<template>
	<view class="page-wrap" :data-theme="theme" :style="globalColor.style">
		<header-custom title="" :search-value.sync="searchInput" searchPlaceholder="请输入学校名称" :isSearch="true" @change="onChangeSearch" />
		<view>
			<!-- 空搜索 -->
			<view class="recordsList" v-if="recordsShow"></view>

			<!-- 列表 -->
			<view class="scroll-view" v-else>
				<view class="scroll-view-item" v-for="(item, index) in dataList.list" :key="index">
					<view class="search-title fboxRow Ycenter color-36363A font26" @tap="searchClick(item)">
						{{item.schoolName}}
					</view>
				</view>
				<u-loadmore :status="dataList.loading"></u-loadmore>
			</view>
		</view>
	</view>
</template>

<script>
	import headerCustom from '@/pagesBKS/components/header-custom.vue';
	import {
		searchSchoolList
	} from '@/api/bks.examinee.js'
	export default {
		components: {
			headerCustom
		},
		data() {
			return {
				theme: 'bks-theme',
				globalColor: getApp().globalData.globalColor,
				recordsShow: true,
				searchInput: '',
				dataList: {
					list: [
						// {
						//   id: 1,
						//   logo: 'https://bks.obs.cn-north-4.myhuaweicloud.com:443/setting/bks-logo.png',
						//   name: '备考生备考生备考生备考生备考生备考生备考生备考生备考生备考生备考生',
						//   tags: ['重庆', '本科', '综合'],
						//   popularity: '1.82W'
						// }
					],
					page: 1,
					size: 20,
					count: 0,
					loading: 'none'
				},
				historyList: [],
				prames: {}
			}
		},
		onLoad(options) {
			try {
				var value = uni.getStorageSync('search_list_school')
				if (value) {
					this.historyList = value
				}
			} catch (e) {
				// Do something when catch error
			}
		},
		onReachBottom: function() {
			this._reachBottom()
		},
		methods: {
			_initData() {
				this.dataList = {
					list: [],
					page: 1,
					size: 20,
					count: 0
				}
			},
			_request() {
				// 已经没有数据了
				if (this.dataList.loading == 'nomore') {
					return
				}
				this.dataList.loading = 'loading'
				const reqData = {
					"campusId": "", // 办学层次
					"characteristic": "", // 办学特色
					"collegesId": "", // 办学类型
					"province": '', // 按区域
					"schoolName": this.searchInput,
					"schoolNatureName": "", // 办学性质
					page: this.dataList.page,
					size: this.dataList.size,
				}
				searchSchoolList(reqData).then(res => {
					const total = res.data.pageInfoVO.total
					const countList = [...this.dataList.list, ...res.data.list]
						this.dataList.list = countList
						this.dataList.count = total
					if (countList.length >= total && total > 0 || total <= 0) {
						this.dataList.loading = 'nomore'
					} else {
						this.dataList.loading = 'loading'
					}
				}).catch(err => {
					console.log(err)
					this.dataList.loading = 'nomore';
				})
			},
			_reachBottom() {
				if (this.dataList.size * this.dataList.page < this.dataList.count) {
					this.dataList.loading = 'loading';
					this.dataList.page++;
					this._request();
				} else {
					this.dataList.loading = 'nomore';
				}
			},
			// 搜索改变
			onChangeSearch(e) {
				if (e) {
					this.recordsShow = false
					this._initData()
					this._request()
				} else {
					this.recordsShow = true
				}
			},
			searchClick(item) {
				this.$pageTo('/bks/index/school/index/index', {
					id: item.schoolId
				})
			},
			// 删除历史记录
			deleteClick() {
				try {
					uni.setStorageSync('search_list_school', [])
				} catch (e) {}
				this.historyList = []
			}
		}
	}
</script>

<style lang="scss" scoped>
.filter-header{height: 72rpx;}
.filter-wrap{padding: 0 30rpx}

.filter-key .bksCIcon{margin-left: 10rpx;}

// .scroll-view{height: clac(100% - 130px);}

.recordsList{padding: 10rpx 10rpx 0 30rpx;}
.recordsList .tit{padding-right: 20rpx; height: 54rpx;}
.recordsList .tag{margin:10rpx 20rpx 10rpx 0;padding: 24rpx; height: 54rpx;background-color: #F5F5F9;color:#646466;border-radius: 4rpx;}

.search-title{padding:0 30rpx;height: 84rpx;border-bottom: 1px solid #EBEBF0;}
</style>